// src/router/index.js
import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/problems' // 将根路径重定向到题目列表
    },
    {
      path: '/problems',
      name: 'problem-list',
      component: () => import('@/views/ProblemList.vue')
    },
    {
      path: '/problem/:id',
      name: 'problem-detail',
      component: () => import('@/views/ProblemDetail.vue'),
      props: true // 启用路由参数作为组件props
    }
    // },
    // {
    //   path: '/problem/create',
    //   name: 'problem-create',
    //   component: () => import('@/views/ProblemEdit.vue'),
    //   meta: { requiresAuth: true } // 需要登录的页面
    // },
    // {
    //   path: '/problem/edit/:id',
    //   name: 'problem-edit',
    //   component: () => import('@/views/ProblemEdit.vue'),
    //   props: true,
    //   meta: { requiresAuth: true }
    // },
    // {
    //   path: '/:pathMatch(.*)*', // 404处理
    //   name: 'not-found',
    //   component: () => import('@/views/NotFound.vue')
    // }
  ]
})

// 添加路由守卫（如果需要权限控制）
router.beforeEach((to, from, next) => {
  const isAuthenticated = /* 你的认证状态检查逻辑 */ false
  
  if (to.meta.requiresAuth && !isAuthenticated) {
    next('/login') // 跳转到登录页
  } else {
    next()
  }
})

export default router